﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Taurus.Platform.DTO;
using Taurus.Platform.XML;
using Taurus.Parking.XML;

namespace Taurus.Parking.DTO
{
    class ParkingUser:UserAccount
    {
        private IPersistence<ParkingUser> _per;
        public ParkingUser()
        {
            _per = new ParkingUserPersistence();
            PriorityUsers = new List<string>();
        }

        public ParkingUser(UserAccount ua):this()
        {
            this.Email = ua.Email;
            this.Friends = ua.Friends;
            this.Groups = ua.Groups;
            this.IsPublic = ua.IsPublic;
            this.Name = ua.Name;
            this.Password = ua.Password;
            this.PicFullName = ua.PicFullName;
            this.Signature = ua.Signature;
            this.SmallAccount = ua.SmallAccount;
            this.UID = ua.UID;
        }
        /// <summary>
        /// 我的现金
        /// </summary>
        public string Cash { get; set; }
        /// <summary>
        /// 我的车库
        /// </summary>
        public Garage Garage { get; set; }
        /// <summary>
        /// 优先停靠的车位用户UID
        /// </summary>
        public List<string> PriorityUsers { get; set; }
        /// <summary>
        /// 优先停靠的车位用户
        /// </summary>
        public List<ParkingUser> WrapperPriorityUsers
        {
            get
            {
                List<ParkingUser> list = new List<ParkingUser>();
                foreach (var uid in PriorityUsers)
                {
                    list.Add(_per.GetObject(uid));
                }
                return list;
            }
        }
        /// <summary>
        /// 车库是否满了
        /// </summary>
        /// <returns></returns>
        public bool IsFull()
        {
            bool f = true;
            if (Garage!=null && Garage.MyParks!=null)
            {
                foreach (var p in Garage.MyParks)
                {
                    if (p.Car.ID == 0)
                    {
                        return false;
                    }
                }
            }
            return f;
        }
        /// <summary>
        /// 是否是邻居
        /// </summary>
        /// <returns></returns>
        public bool IsNeighbor
        {
            get { return UID == "1" || UID == "2"; }
        }
    }
}
